package com.dhj.controller;


import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author DaHuaJia
 * @Description HelloController 类
 * @Date 2022-03-20 10:36:12
 */
@RestController
public class HelloController {

    @RequestMapping("/hello")
    @PreAuthorize("hasAuthority('system:test')")
    public String sayHello() {
        return "Hello, Spring.";
    }


    @RequestMapping("/helloAny")
    @PreAuthorize("hasAnyAuthority('admin','system:admin','system:test')")
    public String sayHelloAny() {
        return "Hello, Spring Security.";
    }


    /**
     * 使用自定义鉴权，通过SpEL表达式，调用指定方法。
     */
    @RequestMapping("/helloSelf")
    @PreAuthorize("@dhj.hasDhjAuthority('system:test:end')")
    public String helloSelf() {
        return "Hi, Spring Security.";
    }


    /**
     * 基于配置的鉴权，权限配置在SecurityConfig中
     */
    @RequestMapping("/helloConfig")
    public String helloConfig() {
        return "Hi, Spring Security. Configuration Authorize.";
    }

}
